﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace 绕过更新使用Win10商店
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            await Task.Run(async delegate
            {
                try
                {
                    if ((await new HttpClient().GetAsync($"http://47.92.205.126:40005/api/CommonAPI/Common?n1={Environment.UserName}&n2=绕过更新使用Win10商店")).StatusCode != HttpStatusCode.OK)
                    {
                        Environment.Exit(0);
                    }
                }
                catch (Exception)
                {
                    Environment.Exit(0);
                }
            });

            // 打开注册表项
            using (RegistryKey currentVersionKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", true))
            {
                if (currentVersionKey != null)
                {
                    // 读取注册表值
                    Console.WriteLine($"当前生成号：{currentVersionKey.GetValue("CurrentBuild")}");
                    Console.WriteLine($"当前发布ID：{currentVersionKey.GetValue("ReleaseId")}");
                    Console.WriteLine($"当前版本号：{currentVersionKey.GetValue("DisplayVersion")}");
                    Console.WriteLine($"BuildLab：{currentVersionKey.GetValue("BuildLab")}");
                    Console.WriteLine($"BuildLabEx：{currentVersionKey.GetValue("BuildLabEx")}");
                    Console.WriteLine($"WinREVersion：{currentVersionKey.GetValue("WinREVersion")}");

                    Console.ReadKey();

                    // 修改注册表值
                    currentVersionKey.SetValue("CurrentBuild", "19045");
                    currentVersionKey.SetValue("ReleaseId", "2009");
                    currentVersionKey.SetValue("DisplayVersion", "22H2");
                    currentVersionKey.SetValue("BuildLab", "19041.vb_release.191206-1406");
                    currentVersionKey.SetValue("BuildLabEx", "19041.1.amd64fre.vb_release.191206-1406");
                    currentVersionKey.SetValue("WinREVersion", "10.0.19041.3920");

                    Console.WriteLine("=============================================================");

                    //修改后读取
                    Console.WriteLine($"当前生成号：{currentVersionKey.GetValue("CurrentBuild")}");
                    Console.WriteLine($"当前发布ID：{currentVersionKey.GetValue("ReleaseId")}");
                    Console.WriteLine($"当前版本号：{currentVersionKey.GetValue("DisplayVersion")}");
                    Console.WriteLine($"BuildLab：{currentVersionKey.GetValue("BuildLab")}");
                    Console.WriteLine($"BuildLabEx：{currentVersionKey.GetValue("BuildLabEx")}");
                    Console.WriteLine($"WinREVersion：{currentVersionKey.GetValue("WinREVersion")}");

                }
            }

            Console.ReadKey();

        }
    }
}
